package com.itheima.tlias.service.impl;

import com.itheima.tlias.entity.Dept;
import com.itheima.tlias.mapper.DeptMapper;
import com.itheima.tlias.service.TestInsertDeptServiceOne;
import com.itheima.tlias.service.TestInsertDeptServiceTwo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestInsertDeptServiceOneImpl implements TestInsertDeptServiceOne {

    @Resource
    DeptMapper deptMapper;

    @Resource
    TestInsertDeptServiceTwo two;

    //事务不能用在private方法上
    //当使用try..cath捕获的时候,事务会失效
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    @Override
    public int insertDeptOne() {
        Dept dept = new Dept();
        dept.setName("测试传播One");
        deptMapper.insertDept(dept);
        two.insertDeptTwo();
        return 0;
    }
}
